﻿using AntdUI;
using CommunityToolkit.Mvvm.ComponentModel;
using DocumentFormat.OpenXml.Drawing;
using SqlSugar;

namespace DataCollection.Infrastructure
{
    #region 设备
    public class DeviceItem : AntdUI.NotifyProperty
    {
        public string Number { get; set; } = null!;
        public string PortAddress { get; set; } = null!;
        public string Name { get; set; } = null!;
        public string SlaveAddress { get; set; } = null!;
        public string Baudrate { get; set; } = null!;
        private int CoilStatusCount { get; set; }
        private int InputStatusCount { get; set; }
        private int HoldingRegisterCount { get; set; }
        private int InputRegisterCount { get; set; }
        public string Enable { get; set; } = null!;
        public string Register
        {
            get
            {
                return string.Format("DI:{0}|DO:{1}|HR:{2}|IR:{3}", InputStatusCount, CoilStatusCount, HoldingRegisterCount, InputRegisterCount);
            }
        }

        //AntdUI.CellLink[] _Operation;
        //public AntdUI.CellLink[] Operation
        //{
        //    get => _Operation;
        //    set
        //    {
        //        _Operation = value;
        //        OnPropertyChanged("Operation");
        //    }
        //}

    }
    #endregion

    #region 设备点位
    public class DevicePointItem : AntdUI.NotifyProperty
    {
        public string DeviceNumber { get; set; } = null!;
        public string DeviceName { get; set; } = null!;
        public string DeviceAddress { get; set; } = null!;
        public string Number { get; set; } = null!;
        public string Name { get; set; } = null!;
        public string Address { get; set; } = null!;
        public string PointType { get; set; } = null!;
        public double RangeMax { get; set; }
        public double RangeMin { get; set; }

        public string Range
        {
            get
            {
                if (RangeMin < 0 || RangeMax <= 0)
                {
                    return "---";
                }
                else
                {
                    return string.Format("{0}-{1}", RangeMin, RangeMax);

                }
            }
        }

        public double OutMax { get; set; }
        public double OutMin { get; set; }
        public string Out
        {
            get
            {
                if (OutMin < 0 || OutMax <= 0)
                {
                    return "---";
                }
                else
                {
                    return string.Format("{0}-{1}", OutMin, OutMax);

                }
            }
        }
        public string Amend { get; set; } = string.Empty;
    }
    #endregion

    #region 模板
    public class TemplateItem : AntdUI.NotifyProperty
    {
        public string Number { get; set; } = null!;

        public string PipePosition { get; set; } = null!;

        public double DesignPressure { get; set; }
        public double FirstStagePressure { get; set; }
        public string FirstStageTime { get; set; } = null!;
        public string FirstStageTimeUnit { get; set; } = null!;
        public string FirstStageEstimateWay { get; set; } = null!;
        public string FirstStageEstimateValue { get; set; } = null!;
        public string FirstStage
        {
            get
            {
                if (FirstStagePressure <= 0)
                {
                    return "---";
                }
                else
                {
                    return string.Format("压力：{0}MPa-时长：{1}{2}", FirstStagePressure, FirstStageTime, FirstStageTimeUnit);

                }
            }
        }


        public double SecondStagePressure { get; set; }
        public string SecondStageTime { get; set; } = null!;
        public string SecondStageTimeUnit { get; set; } = null!;
        public string SecondStageEstimateWay { get; set; } = null!;
        public string SecondStageEstimateValue { get; set; } = null!;
        public string SecondStage
        {
            get
            {
                if (SecondStagePressure <= 0)
                {
                    return "---";
                }
                else
                {
                    return string.Format("压力：{0}MPa-时长：{1}{2}", SecondStagePressure, SecondStageTime, SecondStageTimeUnit);

                }
            }
        }

        public double ThirdStagePressure { get; set; }
        public string ThirdStageTime { get; set; } = null!;
        public string ThirdStageTimeUnit { get; set; } = null!;
        public string ThirdStageEstimateWay { get; set; } = null!;
        public string ThirdStageEstimateValue { get; set; } = null!;
        public string ThirdStage
        {
            get
            {
                if (ThirdStagePressure <= 0)
                {
                    return "---";
                }
                else
                {
                    return string.Format("压力：{0}MPa-时长：{1}{2}", ThirdStagePressure, ThirdStageTime, ThirdStageTimeUnit);

                }
            }
        }


        public double IntensityStagePressure { get; set; }
        public string IntensityStageTime { get; set; } = null!;
        public string IntensityStageTimeUnit { get; set; } = null!;
        public string IntensityStageEstimateWay { get; set; } = null!;
        public string IntensityStageEstimateValue { get; set; } = null!;
        public string IntensityStage
        {
            get
            {
                if (IntensityStagePressure <= 0)
                {
                    return "---";
                }
                else
                {
                    return string.Format("压力：{0}MPa-时长：{1}{2}", IntensityStagePressure, IntensityStageTime, IntensityStageTimeUnit);

                }
            }
        }

        public double RigorStagePressure { get; set; }
        public string RigorStageTime { get; set; } = null!;
        public string RigorStageTimeUnit { get; set; } = null!;
        public string RigorStageEstimateWay { get; set; } = null!;
        public string RigorStageEstimateValue { get; set; } = null!;
        public string RigorStage
        {
            get
            {
                if (RigorStagePressure <= 0)
                {
                    return "---";
                }
                else
                {
                    return string.Format("压力：{0}MPa-时长：{1}{2}", RigorStagePressure, RigorStageTime, RigorStageTimeUnit);

                }
            }
        }

        public string ErrorRange { get; set; } = null!;

        public string StageCount { get; set; } = null!;
    }
    #endregion

    #region 试压工程
    public class ProjectItem : AntdUI.NotifyProperty
    {
        public string Number { get; set; } = null!;

        public string Name { get; set; } = null!;

        public string StakeMark { get; set; } = null!;

        public string PipeSpecification { get; set; } = null!;

        public string PipeLength { get; set; } = null!;

        public string Medium { get; set; } = null!;

        public string DesignPressure { get; set; } = null!;

        public string PipeNature { get; set; } = null!;

        public string TestType { get; set; } = null!;

        public string Company { get; set; } = null!;

        public string ManometerPrecision { get; set; } = null!;

        public string ManometerRange { get; set; } = null!;

        public string TemplateID { get; set; } = null!;
    }
    #endregion

    #region 界面点位

    public class FormPointItem : AntdUI.NotifyProperty
    {
        public string Number { get; set; } = null!;

        public string Name { get; set; } = null!;

        public string DevicePointNumber { get; set; } = null!;

        public string FormControlName { get; set; } = null!;
    }
    #endregion

    #region 历史记录
    public class HistoryItem : AntdUI.NotifyProperty
    {
        public string Number { get; set; } = null!;

        public string ProjectNumber { get; set; } = null!;

        public string ProjectName { get; set; } = null!;

        private string _StartTime = string.Empty;

        public string StartTime 
        {
            get 
            {
                DateTime time = Util.ConvertToDateTime(long.Parse(_StartTime));
                return time.ToString("yyyy-MM-dd HH:mm:ss");
            }

            set 
            {
                _StartTime = value;
            } 
        }

        private string _EndTime = string.Empty;
        public string EndTime
        {
            get
            {
                DateTime time = Util.ConvertToDateTime(long.Parse(_EndTime));
                return time.ToString("yyyy-MM-dd HH:mm:ss");
            }

            set
            {
                _EndTime = value;
            }

        }

        public AntdUI.CellButton[] Operation
        {
            get {
                //return new AntdUI.CellLink[] {
                //    //new AntdUI.CellButton("edit") { BorderWidth=1, IconSvg="EditOutlined"},
                //    new AntdUI.CellButton("point") { BorderWidth=1, IconSvg="ApartmentOutlined"},
                //    //new AntdUI.CellButton("delete") { BorderWidth=1, IconSvg="DeleteOutlined"},
                //};
                return new AntdUI.CellButton[] {
                    new CellButton("export","导出点位",TTypeMini.Primary),
                    //new CellButton("report","导出点位",TTypeMini.Primary)
                };
            }
        }
    }
    #endregion

    #region 历史记录点位
    public class HistoryDataItem : AntdUI.NotifyProperty
    {
        public string MainPressure { get; set; } = null!;
        public string MainMediumTemperature { get; set; } = null!;
        public string MainBattery { get; set; } = null!;
        public string RemotePressure { get; set; } = null!;
        public string RemoteMediumTemperature { get; set; } = null!;
        public string RemoteBattery { get; set; } = null!;
        private string _Time = string.Empty;
        public string Time 
        {
            get
            {
                DateTime time = Util.ConvertToDateTime(long.Parse(_Time));
                return time.ToString("yyyy-MM-dd HH:mm:ss");
            }

            set
            {
                _Time = value;
            }
        }
    }
    #endregion
}
